package secondary.proxy;

import jade.content.Concept;
import jade.content.ContentElement;
import jade.content.lang.Codec;
import jade.content.lang.sl.SLCodec;
import jade.content.onto.Ontology;
import jade.content.onto.basic.Action;
import jade.core.behaviours.CyclicBehaviour;
import jade.lang.acl.ACLMessage;
import ontology.EmploymentLawOntology;
import ontology.UMCourtLOntology;
import ontology.actions.general.AddNewResult;
import ontology.actions.general.GetBATNA;
import ontology.actions.general.GetWATNA;
import classes.UMCourtAgent;
import se.sics.jasper.*;

public class ATNAL extends UMCourtAgent 
{
	private Codec codec = new SLCodec();
	private Ontology ontology = EmploymentLawOntology.getInstance();
	SICStus sp;

	
	protected void setup() 
	{
		System.out.println(getDate()+ ": "+this.getLocalName()+" agent is now running...");
		registerAgent((String)getArguments()[0]);
		
		// Register language and ontology
	    getContentManager().registerLanguage(codec);
	    getContentManager().registerOntology(ontology);
	    
	    try 
	    {
	    	SICStus sp = new SICStus("ATNA.pl");
	        
			
		} 
	    catch (SPException e) 
	    {
			e.printStackTrace();
		}
	    
		
		this.addBehaviour(new receiveBehaviour());
	}
	
	class receiveBehaviour extends CyclicBehaviour
	{
		@Override
		public void action() 
		{
			ACLMessage msg = receive();
	        if (msg == null) 
	        { 
	        	block(); 
	        	return; 
	        }
	        
	        try 
			{
	        	ContentElement content = getContentManager().extractContent(msg);
		        Concept action = ((Action)content).getAction();
         		
		        switch (msg.getPerformative()) 
		        {
		        case (ACLMessage.REQUEST):
			        if (action instanceof GetBATNA)
			        {
			        	content = getContentManager().extractContent(msg);
			            GetBATNA gb = (GetBATNA) ((Action)content).getAction();
			           
			        }
			        if (action instanceof GetWATNA)
			        {
			        	content = getContentManager().extractContent(msg);
			            GetWATNA gw = (GetWATNA) ((Action)content).getAction();
			           
			        }
		        }
			}
	        catch(Exception e){e.printStackTrace();}
		}
	}
}
